package com.xyx.yfy_site_msg.system.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @title: TreeNodeBuilder
 * @projectName yfy_site_msg
 * @description: TODO
 * @date 2020/11/11 0011
 */
public class TreeNodeBuilder {
    
    public static List<TreeNode> build(List<TreeNode> treeNodes, Integer topPid){
        List<TreeNode> nodes=new ArrayList<>();
        for (TreeNode n1 : treeNodes) {
            if (n1.getPid()==topPid) {
                nodes.add(n1);
            }
            for (TreeNode n2 : treeNodes) {
                if (n1.getId()==n2.getPid()) {
                    n1.getChildren().add(n2);
                }
            }
        }
        return nodes;
    }


}
